package com.ja.openchat.ui.found;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.LinearLayoutManager;

import com.ja.openchat.BR;
import com.ja.openchat.R;
import com.ja.openchat.adapters.node.section.NodeSectionAdapter;
import com.ja.openchat.databinding.DynamicDetailsHeadViewBinding;
import com.ja.openchat.databinding.FragmentDynamicDetailsBinding;
import com.ja.openchat.viewmodels.DynamicDetailsViewModel;
import com.scwang.smart.refresh.layout.api.RefreshLayout;
import com.scwang.smart.refresh.layout.listener.OnRefreshListener;

import me.goldze.mvvmhabit.base.BaseFragment;

//动态详情
public class DynamicDetailsFragment extends BaseFragment<FragmentDynamicDetailsBinding, DynamicDetailsViewModel> {
    NodeSectionAdapter nodeAdapter;
    DynamicDetailsHeadViewBinding headerBinding;

    @Override
    public int initContentView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return R.layout.fragment_dynamic_details;
    }

    @Override
    public int initVariableId() {
        return BR.viewModel;
    }

    @Override
    public void initView() {
        super.initView();
        binding.refreshLayout.setEnableLoadMore(false);
        binding.refreshLayout.setOnRefreshListener(new OnRefreshListener() {
            @Override
            public void onRefresh(@NonNull RefreshLayout refreshLayout) {
                binding.refreshLayout.finishRefresh();
            }
        });
        binding.recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
        nodeAdapter = new NodeSectionAdapter();
        headerBinding = DataBindingUtil.inflate(getLayoutInflater(), R.layout.dynamic_details_head_view, binding.recyclerView, false);
        nodeAdapter.addHeaderView(headerBinding.getRoot());
        headerBinding.setViewModel(viewModel);
        binding.recyclerView.setAdapter(nodeAdapter);
        nodeAdapter.setList(viewModel.getEntityData());
        binding.recyclerView.scheduleLayoutAnimation();
    }
}